package com.dcm360.report.system.controller;

import java.util.List;

import com.dcm360.report.controller.BaseController;
import com.dcm360.report.controller.page.TableDataInfo;
import com.dcm360.report.system.domain.SysRole;
import com.dcm360.report.system.service.ISysRoleService;
import com.dcm360.report.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色信息Controller
 * 
 * @author ruoyi
 * @date 2022-04-20
 */
@Api("角色信息管理")
@RestController
@RequestMapping("/role")
public class SysRoleController extends BaseController {
    @Autowired
    private ISysRoleService sysRoleService;

    /**
     * 查询角色信息列表
     */
    @ApiOperation("查询角色信息列表")
    @GetMapping("/list")
    public TableDataInfo list(SysRole sysRole){
        startPage();
        List<SysRole> list = sysRoleService.selectSysRoleList(sysRole);
        return getDataTable(list);
    }


    /**
     * 获取角色信息详细信息
     */
    @ApiOperation("获取角色信息详细信息")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId){
        return AjaxResult.success(sysRoleService.selectSysRoleById(roleId));
    }

    /**
     * 新增角色信息
     */
    @ApiOperation("新增角色信息")
    @PostMapping
    public AjaxResult add(@RequestBody SysRole sysRole){
        return toAjax(sysRoleService.insertSysRole(sysRole));
    }

    /**
     * 修改角色信息
     */
    @ApiOperation("修改角色信息")
    @PutMapping
    public AjaxResult edit(@RequestBody SysRole sysRole){
        return toAjax(sysRoleService.updateSysRole(sysRole));
    }

    /**
     * 删除角色信息
     */
    @ApiOperation("删除角色信息")
	@DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds){
        return toAjax(sysRoleService.deleteSysRoleByIds(roleIds));
    }
}
